# Execution Engine

The Execution Engine is the core execution layer responsible for orchestrating tool calls, managing context windows, and enforcing safety constraints during agent operation.

## Responsibilities

- **Tool dispatch** – routes tool invocations to registered handlers and collects results
- **Context management** – tracks token usage, compresses history when approaching limits
- **Guardrails** – enforces rate limits, blocks disallowed actions, applies content filters
- **Lifecycle hooks** – emits events at each stage (pre-tool, post-tool, on-error) for observability

## Key Components

| Component | Module | Description |
|-----------|--------|-------------|
| Dispatcher | `runtime/dispatch.py` | Matches tool calls to handlers |
| ContextManager | `runtime/context.py` | Sliding-window history management |
| PolicyEngine | `runtime/policy.py` | Evaluates safety rules per action |
| EventBus | `runtime/events.py` | Pub/sub for lifecycle hooks |

## Configuration

```yaml
runtime:
  max_tokens: 200000
  tool_timeout_s: 120
  max_concurrent_tools: 4
  policy: strict
```

## Related

- [[System Overview]]
- [[Q2 Roadmap]]
- [[API Gateway]]
